import renohomeRightNav from '@/components/CustormStyle/renohome_right_nav'
export default {
  data() {
    return {
      nrActive: true,
      fgActive: false,
      $uploadType: -1,
      contentW: 375,
      contentH: 600
    }
  },
  computed: {
    getPath() {
      return function(path) {
        return (path.includes('https://') || path.includes('http://')) ? `${path}` : require(`@/assets/custorm_style/${path}`)
      }
    }
  },
  props: {
    defaultConfig: {
      type: Object,
      required: true
    },
    custormItemData: Object,
    custormEditEvt: Function,
    custormIndex: Number,
    custormCurrent: Number
  },
  components: {
    renohomeRightNav
  },
  methods: {
    alignStyleChange($event, style, isreset) {
      const wr = parseInt(this.contentW / 2 - this.custormItemData.style.width / 2)
      const hr = parseInt(this.contentH / 2 - this.custormItemData.style.height / 2)
      const mr = parseInt(this.contentW - this.custormItemData.style.width)
      const ml = 0
      switch (style) {
        case 'center':
          if ($event === '1') {
            this.custormItemData.style.pos_x = wr
          } else {
            this.custormItemData.style.pos_y = hr
          }
          break
        case 'align':
          if ($event === '1') {
            this.custormItemData.style.pos_x = ml
          } else {
            this.custormItemData.style.pos_x = mr
          }
          break
      }
      // if (isreset) {
      //   this.custormItemData.style[`${style}`] = $event
      // }
    },
    conversionType(type, value) {
      if (type === 'number') {
        return typeof value !== 'number' ? Number(value) : value
      }
    },
    rightNavChange(e) {
      if (e === 'count') {
        this.nrActive = true
        this.fgActive = false
      } else {
        this.nrActive = false
        this.fgActive = true
      }
    },
    changePattern(e) {
      this.$nextTick(() => {
        this.custormItemData.style.display = e
      })
    },
    addItemList({ data, max = null, itemCopy }) {
      const listArr = data
      if (itemCopy) {
        if (typeof max === 'number') {
          const isMax = listArr.length < max
          if (!isMax) {
            this.$message({
              type: 'error',
              message: `添加失败，此组件最多添加${max}个~!`
            })
            return
          }
        }

        this.$nextTick(() => {
          listArr.push(itemCopy)
        })
      }
    },
    delItemList({ data, min = 1, index = -1 }) {
      const listArr = data
      if (index !== -1) {
        if (listArr.length <= min) {
          this.$message({
            type: 'error',
            message: `删除失败，此组件至少保留${min}个`
          })
        } else {
          this.$alert('确定删除此选项？', '提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (action === 'confirm') {
                listArr.splice(index, 1)
                this.$message({
                  type: 'success',
                  message: `删除成功`
                })
              }
            }
          })
        }
      }
    },
    output(config) {
      if (
        Object.prototype.toString.call(this.custormEditEvt) === '[object Function]'
      ) {
        this.$uploadType = config.type || -1
        this.custormEditEvt(config)
      }
    }
  }
}
